/**
 * @file KDNode.hpp
 * @brief 
 * @author Linfu Wei (ghowoght@qq.com)
 * @version 1.0
 * @date 2021-02-24
 * 
 * @copyright Copyright (c) 2021  WHU-EIS
 * 
 */
#ifndef _KDNODE_H
#define _KDNODE_H

#include <vector>
#include <memory>

using std::vector;

enum VECTOR{
    X,
    Y,
    Z,
};

class KDNode {
public:
    using KDNodePtr = std::shared_ptr<KDNode>;
    using point_t = vector<double>;
    point_t point;
    KDNodePtr left;
    KDNodePtr right;
    KDNodePtr front;

    int split = 0;
    double dist = 0;
    double cost = 0;
    
public:
    int dim = 0;

public:
    KDNode() = default;

    KDNode(int x, int y) : point(point_t({(double)x, (double)y})), dim(2) { }

    KDNode(const point_t& point) : point(point), dim(point.size()) {}

    KDNode(const point_t& point, int& split, const KDNodePtr& left, const KDNodePtr& right) : 
            point(point), 
            split(split), 
            left(left), 
            right(right), 
            dim(point.size()) { }

    bool operator>(const KDNode& other) const {
        return dist > other.dist;
    }
    bool operator<(const KDNode& other) const {
        return dist < other.dist;
    }

    bool isEqual(const KDNodePtr& other){
        return point[X] == other->point[X] && point[Y] == other->point[Y];
    }
};


#endif